<?php
session_start();
require_once("../config/include_tokyo.inc.php");
require_once("../class/Common_Function.php");




//get post value
$userName = $_POST["user_name"];
$userPassword = $_POST["user_password"];
$rememberFlag = $_POST["remember_flag"];




//check username/password
$sql_select = "select * from users where user_name='$userName' and user_password='$userPassword'";
$result = $db->Execute($sql_select);
$userId = 0;
while (!$result->EOF) {
			$userId = $result->fields['id'];
			$userName = $result->fields['user_name'];
			$userPassword = $result->fields['user_password'];
			$userRole = $result->fields['user_role'];
			$result->MoveNext();
}
$url = "/";
if($userId > 0){
	//save to cookie
	if ($rememberFlag == 1){
		setcookie("user_name", $userName, time()+3600*24*14,"/");//2周,最后一个参数是路径
	    setcookie("user_password", $userPassword, time()+3600*24*14,"/");
	}
	
	
	//save to session
	$_SESSION['user_name']=$userName;
	$_SESSION['user_password']=$userPassword;
	$_SESSION['user_role']=$userRole;
	$_SESSION['user_id']=$userId;

	//save system message	
	$commonFunction = new Common_Function();
    $_SESSION['current_system']=$commonFunction->getSystem();

	//根据不同角色forward到不同页面;
	if($userRole == 1){//管理员
		//$url =  "../task/taskList.php";
		$url =  "../order/orderList.php";
	}else if($userRole == 2){//快递员
		$url =  "../express/expressList.php";
	}else if($userRole == 3){//跟单员
		$url =  "../tracking/trackingList.php";
	}else if($userRole == 4){//订单管理员
		$url =  "../order/orderList.php";
	}else if($userRole == 5){//任务管理员+订单管理员
		$url =  "../order/orderList.php";
	}else if($userRole == 6){//e邮宝 代理
		$url =  "../express/eub.php";
	}else if($userRole == 7){//女装
		$url =  "../clothing/financialList.php";
	}else if($userRole == 8){//团队成员
		$url =  "../team/myDiary.php";
	}else{
		$url = "../index.php?loginError=1";
	}
}else{
	//forward to login page; show "登录失败"
	$url = "../index.php?loginError=1";
}



echo "<script language='javascript' type='text/javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "用户登录"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
登录验证中……

</body>




</html>



